package com.naja.cdc.develop.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.naja.cdc.framework.provider.database.BinlogDatabaseInfo;
import com.naja.cdc.framework.provider.database.DatabaseInfoProvider;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

/**
 * @auther wangjianying
 * @date 2024/02/04 17:07
 * cdc-framework内置支持了 DruidDataSource/BeeDataSource/Dbcp2/HikariDataSource
 * 这里提供了拓展
 */
@Component
public class DemoDatabaseInfoProvider implements DatabaseInfoProvider {
    @Override
    public BinlogDatabaseInfo getBinlogDatabaseInfo(DataSource dataSource) {
        DruidDataSource druidDataSource = (DruidDataSource) dataSource;
        String password = druidDataSource.getPassword();
        String username = druidDataSource.getUsername();
        String url = druidDataSource.getUrl();
        return createBinlogDatabaseInfo(username, password, url);
    }

    @Override
    public boolean support(DataSource dataSource) {
        return false;
    }

}
